<template>
	<view>
		<uv-sticky bgColor="#f4f5f8" offset-top="-44">
			<uv-tabs :list="list" :current="current" @change="onChange"
				:activeStyle="{color: '#000000',transform: 'scale(1.05)',fontSize:'15px' }"
				:inactiveStyle="{color: '#A2A4A6', transform: 'scale(1)' ,fontSize:'16px'}" itemStyle=" height: 44px;"
				:lineColor="`url(../../static/slider.png) 100% 100%`" lineHeight="7" lineWidth="26"></uv-tabs>
				<!--   -->
		</uv-sticky>
		<editInfo v-if="current==0" @getCurrent="getCurrent" :userForm="userForm"></editInfo>
		<editHalfInfo :otherUserForm="otherUserForm" :userForm="userForm" v-else />
	</view>
</template>

<script>
	import editInfo from "./component/eidtInfo.vue"
	import editHalfInfo from "./component/editHalfInfo.vue";
	import {profileInfo} from '@/api/account';
	export default {
	components:{editInfo,editHalfInfo},
		data() {
			return {
				list: [{
					name: '个人资料'
				}, {
					name: '对另一半期望'
				}],
				current: 0,
				userForm: {
					nick_name: '',
					avatar: '',
					gender: '',
					birthday: '2000-12-25',
					region: ['广东省', '广州市', '海珠区'],
					regionName: '',
					height: '',
					weight: '',
					degree: '大专',
					income: '5万以下',
					// red_book_id: '',
					wechat_id:'',
					character: '',
					hobby: '',
					photos: [],
					du_bai: '',
					identity_photos: [],
					degree_photos: [],
					income_photos: [],
					// audit_expect: '123',
					// status: 2
				},
				otherUserForm: {
					want_gender: '',
					want_year: '',
					want_region: ['广东省', '广州市', '海珠区'],
					regionName: '',
					want_height: '',
					want_weight: '',
					want_degree: '大专',
					want_income: '5万以下',
					want_character: '',
					want_other: '',
				},
				genderList: ['男', '女'],
				degreeList: ['小学', '初中', '高中', '大专', '本科', '硕士', '博士'],
				incomeList: ['5万以下', '5万-10万', '10万-15万', '15万-20万', '20万-30万', '30-40万', '40-50万', '50-100万', '100万以上'],
			};
		},
		onLoad() {
			// 获取个人资料
			profileInfo().then(res => {
				const info = Object.keys(res).reduce(
				  (value, key) => !key.startsWith('want_') ? { ...value, [key]: res[key] } : value,
				  {}
				);
				this.userForm = info
				if (this.userForm.identity_photos == null) {
					this.userForm.identity_photos = []
				}
				if (this.userForm.degree_photos == null) {
					this.userForm.degree_photos = []
				}
				if (this.userForm.income_photos == null) {
					this.userForm.income_photos = []
				}
				
				const otherInfo = Object.keys(res).reduce(
				  (value, key) => key.startsWith('want_') ? { ...value, [key]: res[key] } : value,
				  {}
				);
				this.otherUserForm = otherInfo
				if (this.otherUserForm.want_region == null) {
					this.otherUserForm.want_region = ['广东省', '广州市', '海珠区']
				}
				const gender_index = this.genderList.indexOf(res.gender)
				if (gender_index !== -1) {
					this.userForm.gender = this.genderList[gender_index]
				}
			
				this.userForm.regionName = res.region.join('，')
				this.userForm.weight = res.weight.match(/\d+/)[0]
		
			
				const degree_index = this.degreeList.indexOf(res.degree)
				if (degree_index !== -1) {
					this.userForm.degree = this.degreeList[degree_index]
				}
				const income_index = this.incomeList.indexOf(res.income)
				if (income_index !== -1) {
					this.userForm.income = this.incomeList[income_index]
				}
				

				console.log(this.userForm,this.otherUserForm)
				// this.userForm.nick_name = res.nick_name
				// this.userForm.avatar = res.avatar
				// this.userForm.birthday = res.birthday
				// this.userForm.height = res.height
				// this.red_book_id = res.red_book_id
				// this.userForm.wechat_id = res.wechat_id
				// this.userForm.character = res.character
				// this.userForm.hobby = res.hobby
				// this.userForm.phone = res.phone
				// this.userForm.photos = res.photos
				// this.userForm.switch_show_photo = res.switch_show_photo
				// this.userForm.du_bai = res.du_bai
				// this.userForm.audit_expect = res.audit_expect
				// this.userForm.status = res.status
			}).catch(err => {
				console.log(err)
			});
		},
		mounted(){
	
		},
		methods:{
			onChange(item){
				this.current = item.index
			},
			getCurrent(e){
				this.current = e
			}
		}

	}
</script>

<style lang="scss" scoped>

::v-deep .uv-tabs__wrapper__nav{
	background-image: linear-gradient(90deg, #fefdfb, #ffefe0);
	// background-image:url('../../static/love_bg.jpg');
}
::v-deep .uv-tabs__wrapper__nav__item {
			flex: 1 1 0% !important;
		}
</style>
